/**
 * 完成加载提示信息
 */
function toast(text){
	var content = '已完成';
	if(text != null && text != ""){
		content = text;
	}
	var str = '<div id="toast" style="display: none;">'+
					'<div class="weui-mask_transparent"></div>'+
					'<div class="weui-toast">'+
						'<i class="weui-icon-success-no-circle weui-icon_toast"></i>'+
						'<p class="weui-toast__content">'+content+'</p>'+
					'</div>'+
			  '</div>';
	$(document.body).append(str);
	var $toast = $('#toast');
	if ($toast.css('display') != 'none') return;
    $toast.fadeIn(100);
    setTimeout(function () {
        $toast.fadeOut(100);
    }, 2000);
}

/**
 * 数据加载提示
 */
function loading(){
	var str = '<div id="loadingToast" style="display: none;">'+
					'<div class="weui-mask_transparent"></div>'+
					'<div class="weui-toast">'+
						'<i class="weui-loading weui-icon_toast"></i>'+
						'<p class="weui-toast__content">数据加载中</p>'+
					'</div>'+
			  '</div>';
	$(document.body).append(str);
	
	var $loadingToast = $('#loadingToast');
	if ($loadingToast.css('display') != 'none') return;

    $loadingToast.fadeIn(100);
    setTimeout(function () {
        $loadingToast.fadeOut(100);
    }, 2000);
}

/**
 * 弹出提示框
 */
function weAlert(content,callBack){
	if(content == null || content == ""){
		content = "弹窗内容，告知当前状态、信息和解决方法，描述文字尽量控制在三行内";
	}
	var str = '<div class="js_dialog" id="iosDialog2" style="display: none;">'+
			        '<div class="weui-mask"></div>'+
			        '<div class="weui-dialog">'+
			            '<div class="weui-dialog__bd">'+content+'</div>'+
			            '<div class="weui-dialog__ft">'+
			                '<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">知道了</a>'+
			            '</div>'+
			        '</div>'+
			   '</div>';
	$(document.body).append(str);
	
	$('#iosDialog2').on('click', '.weui-dialog__btn', function(){
        $(this).parents('.js_dialog').fadeOut(200);
        if (typeof (callBack) == 'function') {
        	callBack();
		}
    });
	
	var $iosDialog2 = $('#iosDialog2');
	$iosDialog2.fadeIn(200);
}

/**
 * 弹出确认框
 */
function weConfirm(title,content,callBack){
	if(title == null || title == ""){
		title = "信息确认";
	}
	if(content == null || content == ""){
		content = "弹窗内容，告知当前状态、信息和解决方法，描述文字尽量控制在三行内";
	}
	var str = '<div class="js_dialog" id="iosDialog1" style="display: none;">'+
			        '<div class="weui-mask"></div>'+
			        '<div class="weui-dialog">'+
			            '<div class="weui-dialog__hd"><strong class="weui-dialog__title">'+title+'</strong></div>'+
			            '<div class="weui-dialog__bd">'+content+'</div>'+
			            '<div class="weui-dialog__ft">'+
			                '<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default" id="weConsole">取消</a>'+
			                '<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary" id="weOK">确认</a>'+
			            '</div>'+
			        '</div>'+
			   '</div>';
	$(document.body).append(str);
	
	$("#weOK").on('click',function(){
		$(this).parents('.js_dialog').fadeOut(200);
		if (typeof (callBack) == 'function') {
			callBack();
		}
	});
	
	$("#weConsole").on('click',function(){
		$(this).parents('.js_dialog').fadeOut(200);
	});
	
	var $iosDialog1 = $('#iosDialog1');
	$iosDialog1.fadeIn(200);
}

/**
 * 表单验证错误提示
 */
function formErr(errMsg){
	if($('.js_tooltips')){
		 $('.js_tooltips').remove();
	}
	var str = '<div class="weui-toptips weui-toptips_warn js_tooltips">'+errMsg+'</div>';
	$(document.body).append(str);
	
	var $tooltips = $('.js_tooltips');
	
	if ($tooltips.css('display') != 'none') return;

    // toptips的fixed, 如果有`animation`, `position: fixed`不生效
    $('.page.cell').removeClass('slideIn');

    $tooltips.css('display', 'block');
    setTimeout(function () {
        $tooltips.css('display', 'none');
    }, 2000);
}